package GUI;

import java.awt.FlowLayout;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import papers.Manuscript;
import users.User;

/**
 * A class that allow to change the manuscript status.
 * @author Dickson Kwong
 * revision: Matt Minch
 * @version v1.2 Nov. 30, 2011
 */

@SuppressWarnings("serial")
public class PCViewReviewerPanel extends JPanel {

	/**
	 * The  manuscripts object.
	 */
	private Manuscript my_manu;
	
	/**
	 * The text area that list all the reviewer.
	 */
	private JTextArea my_reviewArea;
	
	/**
	 * The StringBuilder that contains the contain
	 * of the text area.
	 */
	private StringBuilder my_sb;
	
	/**
	 * The JScrollPane.
	 */
	private JScrollPane my_pane;
	
	/**
	 * The reviewer counter.
	 */
	private int reviewer_count;
	
	/**
	 * The PCViewReviewerPanel Constructor. It creates a panel to view
	 * all the reviewer of the paper.
	 * @param the_manuscript The manuscript
	 * @param the_userlist All the users of the conference 
	 */
	public PCViewReviewerPanel(Manuscript the_manuscript, List<User> the_userlist) {
	    super(true);
	    setLayout(new FlowLayout());
	    setSize(200, 600);
	    my_manu = the_manuscript;
	    my_sb = new StringBuilder();
	    my_pane = new JScrollPane();
	    reviewer_count = 1;
	    setup();
	}
	
	private void setup(){	    
	    if(my_manu.getReviewers().size() == 0)
	    {
	    	my_sb.append("No Reviewers");
	    }
	    else
	    {
	    	my_sb.append("Reviewers:\n");
		    for(int i = 0; i < my_manu
		    	.getReviewers().size(); i++){
		    	my_sb.append((i + 1) + ".\t" + my_manu.getReviewers()
		    			.get(i).getName() + "\n");
		    	reviewer_count++;
		    }
	    }
	    my_reviewArea = new JTextArea(22,40);
	    my_reviewArea.setText(my_sb.toString());
	    my_reviewArea.setLineWrap(true);
	    my_reviewArea.setWrapStyleWord(true);
	    my_reviewArea.setCaretPosition(0);
	    my_pane = new JScrollPane(my_reviewArea);
	    my_pane.setVerticalScrollBarPolicy(
	                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
	    
	    my_pane.setEnabled(true);
	    
	    my_reviewArea.setEditable(false);
	    add(my_pane);
	}

	/**
	 * It add the string the my_sb.
	 * @param s The string
	 */
	public void append(String s){
		if(my_sb.substring(0, 12).compareToIgnoreCase("No Reviewers") == 0)
		{
			my_sb.replace(0, 12, "Reviewers:\n");
		}
		my_sb.append(reviewer_count++ + ".\t" + s + "\n");
		my_pane.removeAll();
		my_reviewArea = new JTextArea(30,30);
	    my_reviewArea.setText(my_sb.toString());
	    my_reviewArea.setLineWrap(true);
	    my_reviewArea.setWrapStyleWord(true);
	    my_reviewArea.setCaretPosition(0);
	    my_pane = new JScrollPane(my_reviewArea);
	    my_pane.setVerticalScrollBarPolicy(
	                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
	    my_pane.setEnabled(true);
	    my_reviewArea.setEditable(false);
	    add(my_pane);		
	}
}
